package com.zhq.blog.manage.domain.controller.game;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zhq.blog.core.domain.game.Game;
import com.zhq.blog.manage.domain.controller.BaseController;
import com.zhq.blog.manage.domain.controller.BossModel;

/**
 * @title:Luck28Controller.java
 * @package com.zhq.blog.manage.domain.controller.game
 * @author 张恒强
 * @date 2014年12月25日 下午3:58:07
 * @version V1.0
 */
@Controller
@RequestMapping("/admin/game/luck28/*")
public class Luck28Controller extends BaseController{
	
	@RequestMapping(value="edit",method=RequestMethod.GET)
	public BossModel edit(){
		return createModel("/admin/game/index").add("game", context.getGameRepository().find("name", "幸运28").get(0));
	}
	
	@InitBinder(value={"baseNumber","waterScale","deadline"})
	@RequestMapping(value="save",method=RequestMethod.POST)
	public BossModel save(@Valid Game game,BindingResult bindingResult,
			RedirectAttributes redirectAttributes){
		if(bindingResult.hasErrors()){
			return createModel("/admin/game/index").add("game", game);
		}
		context.getGameRepository().save(game);
		
		return createModel("redirect:admin/share").add("successMessage", "修改成功").add("href", "/admin/game/luck28/edit");
	}

}
